uint8_t volatile isTimeToUsmart = 0;		//ÊÇ·ñ¿ÉÒÔÖ´ÐÐ´úÂë£¬Ìõ¼þÎªÖÐ¶ÏÒÑ¾­½ÓÊÕÍêÊý¾Ý
uint16_t volatile usmartDataLen = 0;		//±¾´Î½ÓÊÕµ½µÄÃüÁîµÄ³¤¶È



void uart_event_handle(app_uart_evt_t * p_event)
{
    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
    static uint8_t index = 0;
    uint32_t       err_code;

    switch (p_event->evt_type)
    {
        case APP_UART_DATA_READY:
            UNUSED_VARIABLE(app_uart_get(&USART_RX_BUF[index]));
            index++;

            if ((USART_RX_BUF[index - 1] == '\n') || (index >= (USART_REC_LEN)))
            {
                isTimeToUsmart = 1;  
								usmartDataLen = index-2;			//Êý¾ÝÖÐ²»ÐèÒª»Ø³µ·ûºÅ£¬ÓÉUSMARTÁíÐÐÌí¼Ó 
                index = 0;
            }
            break;

        case APP_UART_COMMUNICATION_ERROR:
            //APP_ERROR_HANDLER(p_event->data.error_communication);
            break;

        case APP_UART_FIFO_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_code);
            break;

        default:
            break;
    }
}

int main(void)
{

	usmart_dev.init(0);

    for (;;)
    {
        power_manage();
				if(isTimeToUsmart)
				{
					isTimeToUsmart = 0;
					usmart_scan();
					usmartDataLen = 0;
				}
    }
}